//
//  MPCSearchBar.h
//  搜索栏定制
//
//  Created by LG on 2017/11/29.
//  Copyright © 2017年 my. All rights reserved.
//

#import <UIKit/UIKit.h>

#define kSearchDefaultImageName @"search"
#define kSearchBarRightButtonDefault @"取消"
#define COLOR_WITH_HEX(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16)) / 255.0 \
green:((float)((hexValue & 0xFF00) >> 8)) / 255.0 blue:((float)(hexValue & 0xFF)) / 255.0 alpha:1.0f]

@class MPCSearchBar;

typedef void(^RightBtnHandler)(NSString *text);
typedef void(^SearchBarHandler)(void);

typedef NS_ENUM(NSInteger , MPCSearchBarType) {
    MPCSearchBarTypeDefault,// 普通输入视图
    MPCSearchBarTypeButton // 按钮视图
};

@protocol MPCSearchBarDelegate <NSObject>
@optional

- (BOOL)searchBarShouldBeginEditing:(MPCSearchBar*)searchBar textfield:(UITextField *)textField;
- (void)searchBarDidBeginEditing:(MPCSearchBar*)searchBar textfield:(UITextField *)textField;
- (BOOL)searchBarShouldEndEditing:(MPCSearchBar*)searchBar textfield:(UITextField *)textField;
- (void)searchBarDidEndEditing:(MPCSearchBar*)searchBar textfield:(UITextField *)textField;
- (void)searchBarDidEndEditing:(MPCSearchBar*)searchBar textfield:(UITextField *)textField reason:(UITextFieldDidEndEditingReason)reason;

- (BOOL)searchBar:(MPCSearchBar*)searchBar textfield:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;

- (BOOL)searchBarShouldClear:(MPCSearchBar*)searchBar textfield:(UITextField *)textField;
- (BOOL)searchBarShouldReturn:(MPCSearchBar*)searchBar textfield:(UITextField *)textField;

@end


@interface MPCSearchBar : UIView

@property (nonatomic, assign) MPCSearchBarType searchBarType;
@property (nonatomic, weak) id<MPCSearchBarDelegate> delegate;

/*
 搜索栏是否只当作一个按钮使用 -- 如果只当作一个按钮使用的话实现 handler
 */
@property (nonatomic, copy) SearchBarHandler handler;

/*
 搜索栏当作一个输入视图
 */

//是否需要展示右侧按钮
@property (nonatomic, assign) BOOL isRightBtnUseable;

//右侧按钮事件
@property (nonatomic, copy) RightBtnHandler rightHandler;

//右侧按钮文本
@property (nonatomic, copy) NSString *rightTitle;

//输入框左侧图片名称
@property (nonatomic, copy) NSString *leftSearchImageName;

//输入区域背景色
@property (nonatomic, strong) UIColor *inputAreaBackgroundColor;

@property (nonatomic, copy) NSString *placeholdText;
@property (nonatomic, copy) NSAttributedString *attributedPlaceholder;

@property (nonatomic, copy)   NSString *text;
@property (nonatomic, copy)   NSAttributedString *attributedText;
@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, strong) UIFont *font;
@property (nonatomic, assign) NSTextAlignment textAlignment;
@property (nonatomic, assign) UITextBorderStyle borderStyle;
@property (nonatomic, assign) UITextFieldViewMode clearViewMode;


- (instancetype)initWithSearchBarType:(MPCSearchBarType)type;

/**
 输入框获得焦点或者释放焦点

 @param becomeFirst 释放获取焦点
 */
- (void)searchBarBecomeFirstResponse:(BOOL)becomeFirst;


@end
